﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO.Ports;
using System.Net;
using System.Net.Sockets;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading;
using HslCommunication.BasicFramework;
using HslCommunication.Core;
using HslCommunication.Core.Net;
using HslCommunication.LogNet;
using HslCommunication.Profinet.Panasonic;
using HslCommunication.Reflection;

namespace HslCommunication.Profinet.LSIS
{
	/// <summary>
	/// <b>[Authorization]</b> LSisServer
	/// </summary>
	// Token: 0x02000081 RID: 129
	public class LSisServer : NetworkDataServerBase
	{
		/// <summary>
		/// LSisServer  
		/// </summary>
		// Token: 0x060009C2 RID: 2498 RVA: 0x000398FC File Offset: 0x00037AFC
		public LSisServer(string CpuType)
		{
			this.pBuffer = new SoftBuffer(65536);
			this.qBuffer = new SoftBuffer(65536);
			this.iBuffer = new SoftBuffer(65536);
			this.uBuffer = new SoftBuffer(65536);
			this.mBuffer = new SoftBuffer(65536);
			this.dBuffer = new SoftBuffer(131072);
			this.tBuffer = new SoftBuffer(131072);
			this.SetCpuType = CpuType;
			base.WordLength = 2;
			base.ByteTransform = new RegularByteTransform();
			this.serialPort = new SerialPort();
		}

		/// <summary>
		/// set plc
		/// </summary>
		// Token: 0x170001A2 RID: 418
		// (get) Token: 0x060009C3 RID: 2499 RVA: 0x000399AF File Offset: 0x00037BAF
		// (set) Token: 0x060009C4 RID: 2500 RVA: 0x000399B7 File Offset: 0x00037BB7
		public string SetCpuType { get; set; }

		/// <inheritdoc cref="M:HslCommunication.Profinet.LSIS.XGBFastEnet.Read(System.String,System.UInt16)" />
		// Token: 0x060009C5 RID: 2501 RVA: 0x000399C0 File Offset: 0x00037BC0
		[HslMqttApi("ReadByteArray", "")]
		public override OperateResult<byte[]> Read(string address, ushort length)
		{
			OperateResult<string> operateResult = this.AnalysisAddressToByteUnit(address, false);
			bool flag = !operateResult.IsSuccess;
			OperateResult<byte[]> result;
			if (flag)
			{
				result = OperateResult.CreateFailedResult<byte[]>(operateResult);
			}
			else
			{
				int index = int.Parse(operateResult.Content.Substring(1));
				char c = operateResult.Content[0];
				char c2 = c;
				if (c2 != 'D')
				{
					if (c2 != 'I')
					{
						switch (c2)
						{
						case 'M':
							return OperateResult.CreateSuccessResult<byte[]>(this.mBuffer.GetBytes(index, (int)length));
						case 'P':
							return OperateResult.CreateSuccessResult<byte[]>(this.pBuffer.GetBytes(index, (int)length));
						case 'Q':
							return OperateResult.CreateSuccessResult<byte[]>(this.qBuffer.GetBytes(index, (int)length));
						case 'T':
							return OperateResult.CreateSuccessResult<byte[]>(this.tBuffer.GetBytes(index, (int)length));
						case 'U':
							return OperateResult.CreateSuccessResult<byte[]>(this.uBuffer.GetBytes(index, (int)length));
						}
						result = new OperateResult<byte[]>(StringResources.Language.NotSupportedDataType);
					}
					else
					{
						result = OperateResult.CreateSuccessResult<byte[]>(this.iBuffer.GetBytes(index, (int)length));
					}
				}
				else
				{
					result = OperateResult.CreateSuccessResult<byte[]>(this.dBuffer.GetBytes(index, (int)length));
				}
			}
			return result;
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.LSIS.XGBFastEnet.Write(System.String,System.Byte[])" />
		// Token: 0x060009C6 RID: 2502 RVA: 0x00039B04 File Offset: 0x00037D04
		[HslMqttApi("WriteByteArray", "")]
		public override OperateResult Write(string address, byte[] value)
		{
			OperateResult<string> operateResult = this.AnalysisAddressToByteUnit(address, false);
			bool flag = !operateResult.IsSuccess;
			OperateResult result;
			if (flag)
			{
				result = OperateResult.CreateFailedResult<byte[]>(operateResult);
			}
			else
			{
				int destIndex = int.Parse(operateResult.Content.Substring(1));
				char c = operateResult.Content[0];
				char c2 = c;
				if (c2 != 'D')
				{
					if (c2 != 'I')
					{
						switch (c2)
						{
						case 'M':
							this.mBuffer.SetBytes(value, destIndex);
							goto IL_10C;
						case 'P':
							this.pBuffer.SetBytes(value, destIndex);
							goto IL_10C;
						case 'Q':
							this.qBuffer.SetBytes(value, destIndex);
							goto IL_10C;
						case 'T':
							this.tBuffer.SetBytes(value, destIndex);
							goto IL_10C;
						case 'U':
							this.uBuffer.SetBytes(value, destIndex);
							goto IL_10C;
						}
						return new OperateResult<byte[]>(StringResources.Language.NotSupportedDataType);
					}
					this.iBuffer.SetBytes(value, destIndex);
				}
				else
				{
					this.dBuffer.SetBytes(value, destIndex);
				}
				IL_10C:
				result = OperateResult.CreateSuccessResult();
			}
			return result;
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.LSIS.XGBFastEnet.ReadByte(System.String)" />
		// Token: 0x060009C7 RID: 2503 RVA: 0x0001C2EB File Offset: 0x0001A4EB
		[HslMqttApi("ReadByte", "")]
		public OperateResult<byte> ReadByte(string address)
		{
			return ByteTransformHelper.GetResultFromArray<byte>(this.Read(address, 1));
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.LSIS.XGBFastEnet.Write(System.String,System.Byte)" />
		// Token: 0x060009C8 RID: 2504 RVA: 0x0001C2FA File Offset: 0x0001A4FA
		[HslMqttApi("WriteByte", "")]
		public OperateResult Write(string address, byte value)
		{
			return this.Write(address, new byte[]
			{
				value
			});
		}

		/// <inheritdoc />
		// Token: 0x060009C9 RID: 2505 RVA: 0x00039C28 File Offset: 0x00037E28
		[HslMqttApi("ReadBoolArray", "")]
		public override OperateResult<bool[]> ReadBool(string address, ushort length)
		{
			OperateResult<string> operateResult = this.AnalysisAddressToByteUnit(address, true);
			bool flag = !operateResult.IsSuccess;
			OperateResult<bool[]> result;
			if (flag)
			{
				result = OperateResult.CreateFailedResult<bool[]>(operateResult);
			}
			else
			{
				int destIndex = int.Parse(operateResult.Content.Substring(1));
				char c = operateResult.Content[0];
				char c2 = c;
				if (c2 != 'I')
				{
					switch (c2)
					{
					case 'M':
						return OperateResult.CreateSuccessResult<bool[]>(this.mBuffer.GetBool(destIndex, (int)length));
					case 'N':
					case 'O':
						break;
					case 'P':
						return OperateResult.CreateSuccessResult<bool[]>(this.pBuffer.GetBool(destIndex, (int)length));
					case 'Q':
						return OperateResult.CreateSuccessResult<bool[]>(this.qBuffer.GetBool(destIndex, (int)length));
					default:
						if (c2 == 'U')
						{
							return OperateResult.CreateSuccessResult<bool[]>(this.uBuffer.GetBool(destIndex, (int)length));
						}
						break;
					}
					result = new OperateResult<bool[]>(StringResources.Language.NotSupportedDataType);
				}
				else
				{
					result = OperateResult.CreateSuccessResult<bool[]>(this.iBuffer.GetBool(destIndex, (int)length));
				}
			}
			return result;
		}

		/// <inheritdoc />
		// Token: 0x060009CA RID: 2506 RVA: 0x00039D28 File Offset: 0x00037F28
		[HslMqttApi("WriteBoolArray", "")]
		public override OperateResult Write(string address, bool[] value)
		{
			OperateResult<string> operateResult = this.AnalysisAddressToByteUnit(address, true);
			bool flag = !operateResult.IsSuccess;
			OperateResult result;
			if (flag)
			{
				result = OperateResult.CreateFailedResult<bool[]>(operateResult);
			}
			else
			{
				int destIndex = int.Parse(operateResult.Content.Substring(1));
				char c = operateResult.Content[0];
				char c2 = c;
				if (c2 != 'I')
				{
					switch (c2)
					{
					case 'M':
						this.mBuffer.SetBool(value, destIndex);
						return OperateResult.CreateSuccessResult();
					case 'N':
					case 'O':
						break;
					case 'P':
						this.pBuffer.SetBool(value, destIndex);
						return OperateResult.CreateSuccessResult();
					case 'Q':
						this.qBuffer.SetBool(value, destIndex);
						return OperateResult.CreateSuccessResult();
					default:
						if (c2 == 'U')
						{
							this.uBuffer.SetBool(value, destIndex);
							return OperateResult.CreateSuccessResult();
						}
						break;
					}
					result = new OperateResult(StringResources.Language.NotSupportedDataType);
				}
				else
				{
					this.iBuffer.SetBool(value, destIndex);
					result = OperateResult.CreateSuccessResult();
				}
			}
			return result;
		}

		/// <inheritdoc />
		// Token: 0x060009CB RID: 2507 RVA: 0x00039E30 File Offset: 0x00038030
		protected override void ThreadPoolLoginAfterClientCheck(Socket socket, IPEndPoint endPoint)
		{
			AppSession appSession = new AppSession();
			appSession.IpEndPoint = endPoint;
			appSession.WorkSocket = socket;
			try
			{
				socket.BeginReceive(new byte[0], 0, 0, SocketFlags.None, new AsyncCallback(this.SocketAsyncCallBack), appSession);
				base.AddClient(appSession);
			}
			catch
			{
				socket.Close();
				ILogNet logNet = base.LogNet;
				if (logNet != null)
				{
					logNet.WriteDebug(this.ToString(), string.Format(StringResources.Language.ClientOfflineInfo, endPoint));
				}
			}
		}

		// Token: 0x060009CC RID: 2508 RVA: 0x00039EC4 File Offset: 0x000380C4
		[DebuggerStepThrough]
		private void SocketAsyncCallBack(IAsyncResult ar)
		{
			LSisServer.<SocketAsyncCallBack>d__12 <SocketAsyncCallBack>d__ = new LSisServer.<SocketAsyncCallBack>d__12();
			<SocketAsyncCallBack>d__.<>t__builder = AsyncVoidMethodBuilder.Create();
			<SocketAsyncCallBack>d__.<>4__this = this;
			<SocketAsyncCallBack>d__.ar = ar;
			<SocketAsyncCallBack>d__.<>1__state = -1;
			<SocketAsyncCallBack>d__.<>t__builder.Start<LSisServer.<SocketAsyncCallBack>d__12>(ref <SocketAsyncCallBack>d__);
		}

		// Token: 0x060009CD RID: 2509 RVA: 0x00039F04 File Offset: 0x00038104
		private byte[] ReadByMessage(byte[] packCommand)
		{
			List<byte> list = new List<byte>();
			list.AddRange(this.ReadByCommand(packCommand));
			return list.ToArray();
		}

		// Token: 0x060009CE RID: 2510 RVA: 0x00039F30 File Offset: 0x00038130
		private byte[] ReadByCommand(byte[] command)
		{
			List<byte> list = new List<byte>();
			list.AddRange(command.SelectBegin(20));
			list[9] = 17;
			list[10] = 1;
			list[12] = 160;
			list[13] = 17;
			list[18] = 3;
			List<byte> list2 = list;
			byte[] array = new byte[]
			{
				85,
				0,
				0,
				0,
				8,
				1,
				0,
				0,
				1,
				0
			};
			array[2] = command[22];
			array[3] = command[23];
			list2.AddRange(array);
			int num = (int)command[28];
			string @string = Encoding.ASCII.GetString(command, 31, num - 1);
			bool flag = command[22] == 0;
			byte[] array3;
			if (flag)
			{
				int num2 = Convert.ToInt32(@string.Substring(2));
				byte[] array2;
				if (!this.ReadBool(@string.Substring(0, 2) + (num2 / 16).ToString() + (num2 % 16).ToString("X1")).Content)
				{
					array2 = new byte[1];
				}
				else
				{
					(array2 = new byte[1])[0] = 1;
				}
				array3 = array2;
			}
			else
			{
				bool flag2 = command[22] == 1;
				if (flag2)
				{
					array3 = this.Read(@string, 1).Content;
				}
				else
				{
					bool flag3 = command[22] == 2;
					if (flag3)
					{
						array3 = this.Read(@string, 2).Content;
					}
					else
					{
						bool flag4 = command[22] == 3;
						if (flag4)
						{
							array3 = this.Read(@string, 4).Content;
						}
						else
						{
							bool flag5 = command[22] == 4;
							if (flag5)
							{
								array3 = this.Read(@string, 8).Content;
							}
							else
							{
								bool flag6 = command[22] == 20;
								if (flag6)
								{
									ushort length = BitConverter.ToUInt16(command, 30 + num);
									array3 = this.Read(@string, length).Content;
								}
								else
								{
									array3 = this.Read(@string, 1).Content;
								}
							}
						}
					}
				}
			}
			list.AddRange(BitConverter.GetBytes((ushort)array3.Length));
			list.AddRange(array3);
			list[16] = (byte)(list.Count - 20);
			return list.ToArray();
		}

		// Token: 0x060009CF RID: 2511 RVA: 0x0003A124 File Offset: 0x00038324
		private byte[] WriteByMessage(byte[] packCommand)
		{
			List<byte> list = new List<byte>();
			list.AddRange(packCommand.SelectBegin(20));
			list[9] = 17;
			list[10] = 1;
			list[12] = 160;
			list[13] = 17;
			list[18] = 3;
			list.AddRange(new byte[]
			{
				89,
				0,
				20,
				0,
				8,
				1,
				0,
				0,
				1,
				0
			});
			int num = (int)packCommand[28];
			string @string = Encoding.ASCII.GetString(packCommand, 31, num - 1);
			int length = (int)BitConverter.ToUInt16(packCommand, 30 + num);
			byte[] value = base.ByteTransform.TransByte(packCommand, 32 + num, length);
			bool flag = packCommand[22] == 0;
			if (flag)
			{
				int num2 = Convert.ToInt32(@string.Substring(2));
				this.Write(@string.Substring(0, 2) + (num2 / 16).ToString() + (num2 % 16).ToString("X1"), packCommand[38] > 0);
			}
			else
			{
				this.Write(@string, value);
			}
			list[16] = (byte)(list.Count - 20);
			return list.ToArray();
		}

		/// <inheritdoc />
		// Token: 0x060009D0 RID: 2512 RVA: 0x0003A254 File Offset: 0x00038454
		protected override void LoadFromBytes(byte[] content)
		{
			bool flag = content.Length < 262144;
			if (flag)
			{
				throw new Exception("File is not correct");
			}
			this.pBuffer.SetBytes(content, 0, 0, 65536);
			this.qBuffer.SetBytes(content, 65536, 0, 65536);
			this.mBuffer.SetBytes(content, 131072, 0, 65536);
			this.dBuffer.SetBytes(content, 196608, 0, 65536);
		}

		/// <inheritdoc />
		// Token: 0x060009D1 RID: 2513 RVA: 0x0003A2D8 File Offset: 0x000384D8
		protected override byte[] SaveToBytes()
		{
			byte[] array = new byte[262144];
			Array.Copy(this.pBuffer.GetBytes(), 0, array, 0, 65536);
			Array.Copy(this.qBuffer.GetBytes(), 0, array, 65536, 65536);
			Array.Copy(this.mBuffer.GetBytes(), 0, array, 131072, 65536);
			Array.Copy(this.dBuffer.GetBytes(), 0, array, 196608, 65536);
			return array;
		}

		/// <summary>
		/// NumberStyles HexNumber
		/// </summary>
		/// <param name="value"></param>
		/// <returns></returns>
		// Token: 0x060009D2 RID: 2514 RVA: 0x0003A368 File Offset: 0x00038568
		private static bool IsHex(string value)
		{
			bool flag = string.IsNullOrEmpty(value);
			bool result;
			if (flag)
			{
				result = false;
			}
			else
			{
				bool flag2 = false;
				int i = 0;
				while (i < value.Length)
				{
					char c = value[i];
					char c2 = c;
					switch (c2)
					{
					case 'A':
					case 'B':
					case 'C':
					case 'D':
					case 'E':
					case 'F':
						goto IL_6B;
					default:
						switch (c2)
						{
						case 'a':
						case 'b':
						case 'c':
						case 'd':
						case 'e':
						case 'f':
							goto IL_6B;
						}
						break;
					}
					IL_6F:
					i++;
					continue;
					IL_6B:
					flag2 = true;
					goto IL_6F;
				}
				result = flag2;
			}
			return result;
		}

		/// <summary>
		/// Check the intput string address
		/// </summary>
		/// <param name="address"></param>
		/// <returns></returns>
		// Token: 0x060009D3 RID: 2515 RVA: 0x0003A400 File Offset: 0x00038600
		public static int CheckAddress(string address)
		{
			int result = 0;
			bool flag = LSisServer.IsHex(address);
			if (flag)
			{
				int num;
				bool flag2 = int.TryParse(address, NumberStyles.HexNumber, CultureInfo.CurrentCulture, out num);
				if (flag2)
				{
					result = num;
				}
			}
			else
			{
				result = int.Parse(address);
			}
			return result;
		}

		/// <summary>
		/// 使用默认的参数进行初始化串口，9600波特率，8位数据位，无奇偶校验，1位停止位
		/// </summary>
		/// <param name="com">串口信息</param>
		// Token: 0x060009D4 RID: 2516 RVA: 0x0003A446 File Offset: 0x00038646
		public void StartSerialPort(string com)
		{
			this.StartSerialPort(com, 9600);
		}

		/// <summary>
		/// 使用默认的参数进行初始化串口，8位数据位，无奇偶校验，1位停止位
		/// </summary>
		/// <param name="com">串口信息</param>
		/// <param name="baudRate">波特率</param>
		// Token: 0x060009D5 RID: 2517 RVA: 0x0003A458 File Offset: 0x00038658
		public void StartSerialPort(string com, int baudRate)
		{
			this.StartSerialPort(delegate(SerialPort sp)
			{
				sp.PortName = com;
				sp.BaudRate = baudRate;
				sp.DataBits = 8;
				sp.Parity = Parity.None;
				sp.StopBits = StopBits.One;
			});
		}

		/// <summary>
		/// 使用自定义的初始化方法初始化串口的参数
		/// </summary>
		/// <param name="inni">初始化信息的委托</param>
		// Token: 0x060009D6 RID: 2518 RVA: 0x0003A490 File Offset: 0x00038690
		public void StartSerialPort(Action<SerialPort> inni)
		{
			bool flag = !this.serialPort.IsOpen;
			if (flag)
			{
				if (inni != null)
				{
					inni(this.serialPort);
				}
				this.serialPort.ReadBufferSize = 1024;
				this.serialPort.ReceivedBytesThreshold = 1;
				this.serialPort.Open();
				this.serialPort.DataReceived += this.SerialPort_DataReceived;
			}
		}

		/// <summary>
		/// 关闭串口
		/// </summary>
		// Token: 0x060009D7 RID: 2519 RVA: 0x0003A508 File Offset: 0x00038708
		public void CloseSerialPort()
		{
			bool isOpen = this.serialPort.IsOpen;
			if (isOpen)
			{
				this.serialPort.Close();
			}
		}

		/// <summary>
		/// 接收到串口数据的时候触发
		/// </summary>
		/// <param name="sender">串口对象</param>
		/// <param name="e">消息</param>
		// Token: 0x060009D8 RID: 2520 RVA: 0x0003A534 File Offset: 0x00038734
		private void SerialPort_DataReceived(object sender, SerialDataReceivedEventArgs e)
		{
			SerialPort serialPort = (SerialPort)sender;
			int num = 0;
			byte[] array = new byte[1024];
			byte[] array2 = null;
			for (;;)
			{
				Thread.Sleep(20);
				int num2 = serialPort.Read(array, num, serialPort.BytesToRead);
				num += num2;
				bool flag = num2 == 0;
				if (flag)
				{
					break;
				}
				array2 = new byte[num];
				Array.Copy(array, 0, array2, 0, num2);
			}
			bool flag2 = array2 == null;
			if (!flag2)
			{
				byte[] array3 = SoftBasic.ArrayRemoveLast<byte>(array2, 2);
				bool flag3 = array3[3] == 114;
				if (flag3)
				{
					byte[] array4 = this.ReadSerialByCommand(array3);
					base.RaiseDataReceived(array4);
					this.serialPort.Write(array4, 0, array4.Length);
				}
				else
				{
					bool flag4 = array3[3] == 119;
					if (flag4)
					{
						byte[] array4 = this.WriteSerialByMessage(array3);
						base.RaiseDataReceived(array4);
						this.serialPort.Write(array4, 0, array4.Length);
					}
					else
					{
						this.serialPort.Close();
					}
				}
				bool isStarted = base.IsStarted;
				if (isStarted)
				{
					base.RaiseDataSend(array2);
				}
			}
		}

		// Token: 0x060009D9 RID: 2521 RVA: 0x0003A64C File Offset: 0x0003884C
		private byte[] ReadSerialByCommand(byte[] command)
		{
			List<byte> list = new List<byte>();
			list.Add(6);
			list.AddRange(SoftBasic.BuildAsciiBytesFrom((byte)this.station));
			list.Add(114);
			list.Add(83);
			list.Add(66);
			list.AddRange(Encoding.ASCII.GetBytes("01"));
			int num = int.Parse(Encoding.ASCII.GetString(command, 6, 2));
			int num2 = Convert.ToInt32(Encoding.ASCII.GetString(command, 8 + num, 2), 16);
			string @string = Encoding.ASCII.GetString(command, 9, num - 1);
			byte[] content = this.Read(@string, (ushort)num2).Content;
			list.AddRange(SoftBasic.BuildAsciiBytesFrom((byte)content.Length));
			list.AddRange(SoftBasic.BytesToAsciiBytes(content));
			list.Add(3);
			int num3 = 0;
			for (int i = 0; i < list.Count; i++)
			{
				num3 += (int)list[i];
			}
			list.AddRange(SoftBasic.BuildAsciiBytesFrom((byte)num3));
			return list.ToArray();
		}

		// Token: 0x060009DA RID: 2522 RVA: 0x0003A768 File Offset: 0x00038968
		private byte[] WriteSerialByMessage(byte[] packCommand)
		{
			List<byte> list = new List<byte>();
			string @string = Encoding.ASCII.GetString(packCommand, 3, 3);
			list.Add(6);
			list.AddRange(SoftBasic.BuildAsciiBytesFrom((byte)this.station));
			list.Add(119);
			list.Add(83);
			list.Add(66);
			list.Add(3);
			bool flag = @string == "wSS";
			if (flag)
			{
				string string2 = Encoding.ASCII.GetString(packCommand, 8, 2);
				string string3 = Encoding.ASCII.GetString(packCommand, 11, int.Parse(string2) - 1);
				string string4 = Encoding.ASCII.GetString(packCommand, 10 + int.Parse(string2), 2);
				this.Write(string3, new byte[]
				{
					(string4 == "01") ? 1 : 0
				});
			}
			else
			{
				string string2 = Encoding.ASCII.GetString(packCommand, 6, 2);
				string string3 = Encoding.ASCII.GetString(packCommand, 9, int.Parse(string2) - 1);
				int num = int.Parse(Encoding.ASCII.GetString(packCommand, 8 + int.Parse(string2), 2));
				string string5 = Encoding.ASCII.GetString(packCommand, 8 + int.Parse(string2) + num, num * 2);
				byte[] value = SoftBasic.HexStringToBytes(string5);
				this.Write(string3, value);
			}
			return list.ToArray();
		}

		/// <inheritdoc />
		// Token: 0x060009DB RID: 2523 RVA: 0x0003A8B8 File Offset: 0x00038AB8
		public override string ToString()
		{
			return string.Format("LSisServer[{0}]", base.Port);
		}

		/// <summary>
		/// 将带有数据类型的地址，转换成实际的byte数组的地址信息，例如 MW100 转成 M200
		/// </summary>
		/// <param name="address">带有类型的地址</param>
		/// <param name="isBit">是否是位操作</param>
		/// <returns>最终的按照字节为单位的地址信息</returns>
		// Token: 0x060009DC RID: 2524 RVA: 0x0003A8D0 File Offset: 0x00038AD0
		public OperateResult<string> AnalysisAddressToByteUnit(string address, bool isBit)
		{
			bool flag = !XGBFastEnet.AddressTypes.Contains(address.Substring(0, 1));
			OperateResult<string> result;
			if (flag)
			{
				result = new OperateResult<string>(StringResources.Language.NotSupportedDataType);
			}
			else
			{
				try
				{
					bool flag2 = address[0] == 'D' || address[0] == 'T';
					int num;
					if (flag2)
					{
						char c = address[1];
						char c2 = c;
						if (c2 <= 'D')
						{
							if (c2 == 'B')
							{
								num = Convert.ToInt32(address.Substring(2));
								goto IL_D8;
							}
							if (c2 == 'D')
							{
								num = Convert.ToInt32(address.Substring(2)) * 4;
								goto IL_D8;
							}
						}
						else
						{
							if (c2 == 'L')
							{
								num = Convert.ToInt32(address.Substring(2)) * 8;
								goto IL_D8;
							}
							if (c2 == 'W')
							{
								num = Convert.ToInt32(address.Substring(2)) * 2;
								goto IL_D8;
							}
						}
						num = Convert.ToInt32(address.Substring(1)) * 2;
						IL_D8:;
					}
					else if (isBit)
					{
						char c3 = address[1];
						char c4 = c3;
						if (c4 != 'X')
						{
							num = PanasonicHelper.CalculateComplexAddress(address.Substring(1));
						}
						else
						{
							num = PanasonicHelper.CalculateComplexAddress(address.Substring(2));
						}
					}
					else
					{
						char c5 = address[1];
						char c6 = c5;
						if (c6 <= 'D')
						{
							if (c6 == 'B')
							{
								num = Convert.ToInt32(address.Substring(2));
								goto IL_1C4;
							}
							if (c6 == 'D')
							{
								num = Convert.ToInt32(address.Substring(2)) * 4;
								goto IL_1C4;
							}
						}
						else
						{
							if (c6 == 'L')
							{
								num = Convert.ToInt32(address.Substring(2)) * 8;
								goto IL_1C4;
							}
							if (c6 == 'W')
							{
								num = Convert.ToInt32(address.Substring(2)) * 2;
								goto IL_1C4;
							}
							if (c6 == 'X')
							{
								num = Convert.ToInt32(address.Substring(2));
								goto IL_1C4;
							}
						}
						num = Convert.ToInt32(address.Substring(1)) * (isBit ? 1 : 2);
						IL_1C4:;
					}
					result = OperateResult.CreateSuccessResult<string>(address.Substring(0, 1) + num.ToString());
				}
				catch (Exception ex)
				{
					result = new OperateResult<string>("AnalysisAddress Failed: " + ex.Message + " Source: " + address);
				}
			}
			return result;
		}

		// Token: 0x040002E3 RID: 739
		private SoftBuffer pBuffer;

		// Token: 0x040002E4 RID: 740
		private SoftBuffer qBuffer;

		// Token: 0x040002E5 RID: 741
		private SoftBuffer mBuffer;

		// Token: 0x040002E6 RID: 742
		private SoftBuffer iBuffer;

		// Token: 0x040002E7 RID: 743
		private SoftBuffer uBuffer;

		// Token: 0x040002E8 RID: 744
		private SoftBuffer dBuffer;

		// Token: 0x040002E9 RID: 745
		private SoftBuffer tBuffer;

		// Token: 0x040002EA RID: 746
		private const int DataPoolLength = 65536;

		// Token: 0x040002EB RID: 747
		private int station = 1;

		// Token: 0x040002EC RID: 748
		private SerialPort serialPort;
	}
}
